package com.atguigu.srb.core.controller.api;


import com.atguigu.common.result.R;
import com.atguigu.common.utils.JwtUtils;
import com.atguigu.srb.core.pojo.vo.InvestVO;
import com.atguigu.srb.core.service.LendItemService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;

/**
 * <p>
 * 标的出借记录表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2022-09-13
 */
@RestController
@RequestMapping("/api/core/lendItem")
public class ApiLendItemController {


    @Resource
    LendItemService lendItemService;

    @GetMapping("/getInterestCount/{investAmount}/{lendId}")
    public R getInterestCount(HttpServletRequest request,
            @PathVariable BigDecimal investAmount , @PathVariable Long lendId){
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        BigDecimal interestCount = lendItemService.getInterestCount(investAmount,lendId,userId);
        return R.ok().data("interestCount",interestCount);
    }

    @PostMapping("/commitInvest")
    public R commitInvest(@RequestBody InvestVO investVO,HttpServletRequest request){
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        String form = lendItemService.commitInvest(investVO,userId);
        return R.ok().data("form",form);
    }

}

